#!/bin/sh



#############################
# function setupPaths {}    #
#                           #
# Set up installation paths #
#############################
function setupPaths {
    # License Control paths.
    LIBRARY_FOLDER="/Library/";
    APP_SUPPORT_FOLDER="$LIBRARY_FOLDER""Application Support/";
    SYNCROSOFT_LEGACY_FOLDER="$APP_SUPPORT_FOLDER""Syncrosoft/";
    ELICENSER_FOLDER="$APP_SUPPORT_FOLDER""eLicenser/";
    POS_COMPONENTS_PARENT_PATH="$ELICENSER_FOLDER""pos/";

    # Soft-eLicenser paths.
    SEL_STORAGE_NAME="SeLicenser.sel";
    SEL_FOLDER="$APP_SUPPORT_FOLDER""Soft-eLicenser/";
    SEL_LEGACY_FOLDER="$APP_SUPPORT_FOLDER""Syncrosoft Soft-eLicenser/";
    SEL_STORAGE_FILE_PATH="$SEL_FOLDER""$SEL_STORAGE_NAME";
    SEL_LEGACY_STORAGE_FILE_PATH="$SEL_LEGACY_FOLDER""$SEL_STORAGE_NAME";

    # Legacy log file paths.
    PATH_TO_LEGACY_USER_LOG_PARRENT_FOLDER="$HOME/Library/Logs/Syncrosoft/";
    PATH_TO_LEGACY_USER_LOG_FOLDER="$PATH_TO_LEGACY_USER_LOG_PARRENT_FOLDER/LCC/";
    PATH_TO_LEGACY_GLOBAL_LOG_PARRENT_FOLDER="/Library/Logs/Syncrosoft/";

    # Current log file paths.
    PATH_TO_USER_LOG_FOLDER="$HOME/Library/Logs/eLicenser/";
} # setupPaths
###############



##############################################################
# Remove files left over by older versions of this installer #
##############################################################
function cleanup {
    # Removing old installation files in case previous runs of the eLicenser Control installer failed
    /bin/echo "Removing old log files...";

    PATH_TO_INSTALLATION_OLD="/private/tmp/SyncrosoftLicenseControlInstaller_tmp_folder";
    if [ -d "$PATH_TO_INSTALLATION_OLD" ]; then
        /bin/rm -R "$PATH_TO_INSTALLATION_OLD";
    fi

    if [ -d "$PATH_TO_INSTALLATION_OLD" ]; then
        /bin/echo "ERROR: Could not remove previous installation remainders: ""$PATH_TO_INSTALLATION_OLD";
        exit 1;
    fi

    PATH_TO_INSTALLATION_NEW="/private/tmp/eLicenserControl_installer_tmp_folder";
    if [ -d "$PATH_TO_INSTALLATION_NEW" ]; then
        /bin/rm -R "$PATH_TO_INSTALLATION_NEW";
    fi

    if [ -d "$PATH_TO_INSTALLATION_NEW" ]; then
        /bin/echo "ERROR: Could not remove previous installation remainders: ""$PATH_TO_INSTALLATION_NEW";
        exit 1;
    fi

    /bin/echo "... ready removing old files."
} # cleanup
############





#############
# Main code #
#############

/bin/echo "Running preflight script";

setupPaths;
cleanup;

/bin/echo "... finished running preflight script."

exit 0;
